import { $ } from "../modules/public.js";
import ajax from "../modules/ajax.js";
import toast from "../modules/toast.js";

ajax({
  url:"http://localhost:3000/getuser",
  data:{
    token: sessionStorage.getItem("token") || ""
  }
}).then(res=>{
  res = JSON.parse(res);
  if(res.code === 0){
    $(".welcomeMsg").style.display = "none";
    $(".loginMsg").style.display = "block";
    toast({
      type:"error",
      title:"登录失效或未登录"
    })
  }else{
    $(".welcomeMsg").style.display = "block";
    $(".loginMsg").style.display = "none";
    $(".welcomeMsg a").innerHTML = res.data.nickName || res.data.tel;
  }
})

$(".welcomeMsg em").onclick = function(){
  sessionStorage.removeItem("token");
  $(".welcomeMsg").style.display = "none";
  $(".loginMsg").style.display = "block";
}